package tools;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import domain.Stu;
import service.StuService;
import service.Impl.StuServiceImpl;

public class WriteTool {
	private String path;
	private List<Stu>list;
	StuService stuService=new StuServiceImpl();//注入service
	public List<Stu> getList() {
		return list;
	}

	public void setList(List<Stu> list) {
		this.list = list;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public boolean writeAsFile() {
		BufferedWriter bw=null;
		boolean flag=false;
		try {
			bw=new BufferedWriter(new FileWriter(path,true));
			for(Stu s:list) {
				String id=s.getID()+"";
				String name=s.getName();
				String classes=s.getClasses();
				String Course=s.getCourse();
				String score=s.getScore();
//				String str=id+","+name+","+Course+","+classes+","+score;
				StringBuffer sb=new StringBuffer();
				sb.append(id+",");sb.append(name+",");sb.append(Course+",");sb.append(classes+",");sb.append(score);
				String str=sb.toString();
				bw.write(str);
				bw.newLine();
				bw.flush();
				flag=true;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}
}
